package com.jugheadzhou.practice.newcoder;


import java.util.*;

public class LURSolution {

    private final LinkedHashMap<Integer, Integer> cache;

    public LURSolution(final int capacity) {

        this.cache = new LinkedHashMap((int) (capacity / 0.75f + 2), 0.75f, true) {
            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return this.size() > capacity;
            }
        };

    }

    public int get(int key) {
        Integer v = cache.get(key);

        return v == null ? -1 : v;
    }

    public void set(int key, int value) {
        cache.put(key, value);
    }


}
